package com.aaa.boot.controller;

import com.aaa.boot.pojo.dto.AdminDTO;
import com.aaa.boot.service.AdminService;
import com.aaa.boot.util.AjaxResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private HttpSession  session;
    @Autowired
    private AdminService adminService;
    @PostMapping("login")
    @ApiOperation(value = "用户登录")
    public AjaxResult login(String phone, String password,String code){
        AdminDTO adminInfo = null;
        if(password.equals("")){
            //验证码登录
            adminInfo = adminService.loginCode(phone, code);
        }else{
            adminInfo = adminService.loginPassword(phone, password);
            session.setAttribute("adminInfo",adminInfo);
        }
        return AjaxResult.success("登录成功",adminInfo);
    }

    @PostMapping("register")
    @ApiOperation(value = "用户注册")
    public AjaxResult register(String userName,String phone, String password,String code){
        return adminService.register(userName,phone, password);
    }
}
